package com.homeorder.action;

import java.util.List;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.homeorder.entity.OrderInfo;
import com.homeorder.service.OrderServiceImpl;
import com.opensymphony.xwork2.Action;

public class OrderAction {
	private OrderInfo order;
	private OrderServiceImpl oService = new OrderServiceImpl();
	private List<OrderInfo> olist;

	public OrderAction() {
		BeanFactory bf = new ClassPathXmlApplicationContext("applicationContext.xml");
		oService = (OrderServiceImpl) bf.getBean("orderService");		
	}

	public OrderInfo getOrder() {
		return order;
	}

	public void setOrder(OrderInfo order) {
		this.order = order;
	}

	public List<OrderInfo> getOlist() {
		return olist;
	}

	public void setOlist(List<OrderInfo> olist) {
		this.olist = olist;
	}

	public String add() throws Exception {
		order.setFStatus((short) 0);
		if (oService.addOrder(order) > 0) {
			return "list";
		}
		return Action.ERROR;
	}

	public String list() throws Exception {
		olist = oService.getOrders();
		return Action.SUCCESS;
	}
}
